home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2013 July / PCgo_CD_v2_13_07.iso / nw.pak / Unnamed File 000849.txt < prev    next >
Encoding:
Text File  |  2012-12-14  |  3.6 KB  |  106 lines

  1. // Copyright (c) 2012 Intel Corp
  2. // Copyright (c) 2012 The Chromium Authors
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. //  in the Software without restriction, including without limitation the rights
  7. //  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
  8. // pies of the Software, and to permit persons to whom the Software is furnished
  9. //  to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in al
  12. // l copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
  15. // PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
  16. // S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  17. //  OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
  18. // ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. //  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20.  
  21. var v8_util = process.binding('v8_util');
  22.  
  23. function Tray(option) {
  24.   if (typeof option != 'object')
  25.     throw new String('Invalid option');
  26.  
  27.   if (!option.hasOwnProperty('title') && !option.hasOwnProperty('icon'))
  28.     throw new String("Must set 'title' or 'icon' field in option");
  29.  
  30.   if (!option.hasOwnProperty('title'))
  31.     option.title = '';
  32.   else
  33.     option.title = String(option.title);
  34.  
  35.   if (option.hasOwnProperty('icon')) {
  36.     option.shadowIcon = String(option.icon);
  37.     option.icon = nw.getAbsolutePath(option.icon);
  38.   }
  39.  
  40.   if (option.hasOwnProperty('tooltip'))
  41.     option.tooltip = String(option.tooltip);
  42.  
  43.   if (option.hasOwnProperty('menu')) {
  44.     if (v8_util.getConstructorName(option.menu) != 'Menu')
  45.       throw new String("'menu' must be a valid Menu");
  46.  
  47.     // Transfer only object id
  48.     v8_util.setHiddenValue(this, 'menu', option.menu);
  49.     option.menu = option.menu.id;
  50.   }
  51.  
  52.   v8_util.setHiddenValue(this, 'option', option);
  53.   nw.allocateObject(this, option);
  54.  
  55.   // All properties must be set after initialization.
  56.   if (!option.hasOwnProperty('icon'))
  57.     option.shadowIcon = '';
  58.   if (!option.hasOwnProperty('tooltip'))
  59.     option.tooltip = '';
  60. }
  61. require('util').inherits(Tray, exports.Base);
  62.  
  63. Tray.prototype.__defineGetter__('title', function() {
  64.   return this.handleGetter('title');
  65. });
  66.  
  67. Tray.prototype.__defineSetter__('title', function(val) {
  68.   this.handleSetter('title', 'SetTitle', String, val);
  69. });
  70.  
  71. Tray.prototype.__defineGetter__('icon', function() {
  72.   return this.handleGetter('shadowIcon');
  73. });
  74.  
  75. Tray.prototype.__defineSetter__('icon', function(val) {
  76.   v8_util.getHiddenValue(this, 'option').shadowIcon = String(val);
  77.   var real_path = val == '' ? '' : nw.getAbsolutePath(val);
  78.   this.handleSetter('icon', 'SetIcon', String, real_path);
  79. });
  80.  
  81. Tray.prototype.__defineGetter__('tooltip', function() {
  82.   return this.handleGetter('tooltip');
  83. });
  84.  
  85. Tray.prototype.__defineSetter__('tooltip', function(val) {
  86.   this.handleSetter('tooltip', 'SetTooltip', String, val);
  87. });
  88.  
  89. Tray.prototype.__defineGetter__('menu', function() {
  90.   return v8_util.getHiddenValue(this, 'menu');
  91. });
  92.  
  93. Tray.prototype.__defineSetter__('menu', function(val) {
  94.   if (v8_util.getConstructorName(val) != 'Menu')
  95.     throw new String("'menu' property requries a valid Menu");
  96.  
  97.   v8_util.setHiddenValue(this, 'menu', val);
  98.   nw.callObjectMethod(this, 'SetMenu', [ val.id ]);
  99. });
  100.  
  101. Tray.prototype.remove = function() {
  102.   nw.callObjectMethod(this, 'Remove', []);
  103. }
  104.  
  105. exports.Tray = Tray;
  106.